package com.ecable.serviceImpl;

import java.util.Vector;

import com.ecable.bean.StateTO;
import com.ecable.daoI.AddStateDAOI;
import com.ecable.daoImpl.AddStateDAoImpl;
import com.ecable.exception.ConnectionException;
import com.ecable.exception.DataNotFoundException;
import com.ecable.exception.LoginException;
import com.ecable.serviceI.AddStateServiceI;

public class AddStateServiceImpl implements AddStateServiceI {

	boolean flag = false;

	AddStateDAOI adao = new AddStateDAoImpl();

	public boolean insertState(StateTO st) throws LoginException,
			ConnectionException {
		flag = adao.insertState(st);
		if (flag == false) {
			throw new ConnectionException();
		} else if (st.getSname() == null || st.getSname().equals("")) {
			throw new LoginException();
		}
		return flag;
	}

	public Vector<StateTO> viewState() throws ConnectionException,
			DataNotFoundException {

		Vector<StateTO> vsto = adao.viewState();

		if (vsto == null) {
			throw new ConnectionException();

		} else if (vsto.isEmpty()) {

			throw new DataNotFoundException();

		}
		return vsto;

	}

	public StateTO viewStateInfo(int sid) throws DataNotFoundException {

		StateTO sto = adao.viewStateInfo(sid);

		if (sto == null) {

			throw new DataNotFoundException();
		}

		return sto;

	}

	public boolean deleteState(int sid) throws LoginException,
			ConnectionException {

		flag = adao.deleteState(sid);

		if (flag == false) {

			throw new ConnectionException();
		}

		return flag;

	}

	public boolean updateState(StateTO sf) throws LoginException,
			ConnectionException {

		flag = adao.updateState(sf);

		if (flag == false) {

			throw new ConnectionException();
		}

		return flag;
	}

}
